module.exports = {
    css: {
        loaderOptions: {
            stylus: {
                'resolve url': true,
                import: []
            }
        }
    },
    pluginOptions: {
        'cube-ui': {
            postCompile: true,
            theme: false
        }
    },
    lintOnSave: false,
    configureWebpack: {
        devServer: {
            // proxy: {
            //     "/api": {
            //         target: "http://localhost:3003/",
            //         changOrigin: true
            //     }
            // }
            before(app) {
                app.get('/api/login', (req, res) => {
                    const { username, password } = req.query;
                    if (username === "kai" && password === '123') {
                        res.json({ code: 1, token: 'nihao' })
                    } else {
                        res.status(402).json({ code: 0, message: '用户名错误' })
                    }

                });
                //auth--是一个中间件函数-无法通过auth认证的话无法返回给前端

                function auth(req, res, next) {
                    if (req.headers.Authorization) {
                        console.log(1)
                        next()
                    } else {
                        res.status(401)
                            // 只是设置了状态并没有返回
                        res.sendStatus(401)
                    }
                }
                app.get('/api/userinfo', auth, (req, res) => {
                    res.json({ code: 1, data: { name: 'juerry' } })
                })
                app.get("/api/goods", function(req, res) {
                    res.json({
                        code: 1,
                        slider: [{
                                id: 21,
                                img: "/img/02.jpg"
                            },
                            {
                                id: 22,
                                img: "/img/04.jpg"
                            },
                            {
                                id: 23,
                                img: "/img/03.jpg"
                            }

                        ],
                        data: {
                            fe: [{
                                    id: 1,
                                    title: "Vue2.x实战",
                                    price: "100",
                                    img: "/img/01.jpg",
                                    count: 100
                                },
                                {
                                    id: 2,
                                    title: "React16.x实战",
                                    price: "120",
                                    img: "/img/03.jpg",
                                    count: 100
                                },
                                {
                                    id: 3,
                                    title: "nodejs实战",
                                    price: "80",
                                    img: "/img/02.jpg",
                                    count: 100
                                },
                                {
                                    id: 4,
                                    title: "前端工程化",
                                    price: "110",
                                    img: "/img/04.jpg",
                                    count: 100
                                },
                                {
                                    id: 5,
                                    title: "面试",
                                    price: "200",
                                    img: "/img/02.jpg",
                                    count: 100
                                },
                                {
                                    id: 6,
                                    title: "前端安全",
                                    price: "30",
                                    img: "/img/05.jpg",
                                    count: 100
                                }
                            ],
                            python: [{
                                    id: 7,
                                    title: "Python基础语法",
                                    price: "120",
                                    img: "/img/03.jpg",
                                    count: 101
                                },
                                {
                                    id: 8,
                                    title: "Flask实战",
                                    price: "80",
                                    img: "/img/02.jpg",
                                    count: 100
                                },
                                {
                                    id: 9,
                                    title: "Django实战",
                                    price: "110",
                                    img: "/img/01.jpg",
                                    count: 100
                                },
                                {
                                    id: 10,
                                    title: "Python语法进阶",
                                    price: "200",
                                    img: "/img/04.jpg",
                                    count: 100
                                }
                            ],
                            java: [{
                                    id: 11,
                                    title: "java入门实战",
                                    price: "80",
                                    img: "/img/02.jpg",
                                    count: 100
                                },
                                {
                                    id: 12,
                                    title: "spring boot实战",
                                    price: "110",
                                    img: "/img/01.jpg",
                                    count: 100
                                },
                                {
                                    id: 13,
                                    title: "Java高并发",
                                    price: "30",
                                    img: "/img/04.jpg",
                                    count: 100
                                }
                            ],
                            bigdata: [{
                                    id: 14,
                                    title: "大数据实战",
                                    price: "200",
                                    img: "/img/01.jpg",
                                    count: 100
                                },
                                {
                                    id: 15,
                                    title: "Hadoop实战",
                                    price: "120",
                                    img: "/img/03.jpg",
                                    count: 100
                                },
                                {
                                    id: 16,
                                    title: "Kafka平台",
                                    price: "80",
                                    img: "/img/02.jpg",
                                    count: 100
                                }
                            ],
                            ai: [{
                                    id: 17,
                                    title: "算法实战",
                                    price: "100",
                                    img: "/img/01.jpg",
                                    count: 100
                                },
                                {
                                    id: 18,
                                    title: "个性化推荐",
                                    price: "120",
                                    img: "/img/03.jpg",
                                    count: 100
                                },
                                {
                                    id: 19,
                                    title: "机器学习",
                                    price: "80",
                                    img: "/img/02.jpg",
                                    count: 100
                                },
                                {
                                    id: 20,
                                    title: "AI实战",
                                    price: "110",
                                    img: "/img/05.jpg",
                                    count: 100
                                }
                            ]
                        },
                        keys: ["fe", "python", "java", "bigdata", "ai"]
                    });
                });
            }

        }
    }

}